<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 二维数组转换
    var arr = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['j', 'k', 'l']];
    var res = [];

    for (var i = 0; i < arr[0]; i++) {
      res[i] = [];
    }
    //遍历arr数组
    for (var i = 0; i < arr; i++) {
      for (var j = 0; j < arr[i]; j++) {
        res[j][i] = arr[i][j];
      }
    }
    console.log(res);


    //冒泡排序，从大到小

    var arr = [70, 35, 67, 49, 20, 59, 98, 100];
    //外层循环，控制轮数
    for (var i = 1; i < arr.length; i++) {
      // 内层循环，判断两个数的大小
      for (var j = 0; j < arr.length - i; j++) {
        // 白话解释：如果前面的数小，放到后面(从大到小的冒泡排序)
        if (arr[j] < arr[j + 1]) {
          // var temp = arr[j];
          // arr[j] = arr[j + 1];
          // arr[j + 1] = temp;
          [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
        }
      }
    }
    console.log(arr);

    // 输出任意一个二维数组中数据的个数
    var arr02 = [[21, 22, 23, 24, 25, 45, 46], [13, 16, 67, 93]];
    var num = 0;
    for (var v of arr02) {
      num += v.length;
    }
    document.write("数据的总个数为" + num + '</br>');

    // 数组去重
    var arr03 = [23, 45, 67, 92, 84, 67, 78, 90, 84];
    var arr04 = [];
    for (var v of arr03) {
      var isNum = false;
      for (var e of arr04) {
        if (v == e) isNum = true;
      }
      if (!isNum) {
        arr04[arr04.length] = v;
      }
    }
    document.write(arr04);
  </script>
</body>

</html>